﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.7/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!-- 权限验证 -->
    <script type="text/javascript" src="static/WebApi.js"></script>
    <title>部门列表</title>
</head>
<body>
    <!--top 导航-->
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 部门管理 <a class="btn btn-success radius r" id="reloadhref" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>

    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-primary radius" onclick="admin_add('添加部门', 'adddivisionmanagement.html', '600', '350')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i>添加部门</a>
                <input type="text" name="" id="dname_search" placeholder="请输入部门名称查询" style="width:250px" class="input-text">
                <button name="" id="" class="btn btn-success" type="button" onclick="searchDepartment()"><i class="Hui-iconfont">&#xe665;</i> 查询</button>
            </span>
            <span class="r">当前数据：<strong id="count">&nbsp;</strong> 条，共<strong id="pagecount"></strong>页</span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg">
                <thead>
                    <tr class="text-c">
                        <th width="40">序号</th>
                        <th width="150">部门编号</th>
                        <th>部门名称</th>
                        <th width="90">备注</th>
                        <th width="100">是否已启用</th>
                        <th width="100">操作</th>
                    </tr>
                </thead>
                <tbody id="mybody"></tbody>
                <tfoot id="myfoot"></tfoot>
            </table>
        </div>
    </div>
    <!--模态框-->
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--扩展js脚本-->
    <script type="text/javascript" src="static/Common.js"></script>
    <script type="text/javascript">

        //页面加载
        $(document).ready(function () {
            Showdivisionmanagement("", 1, 10);//部门管理显示Department表
        });

        //部门管理,根据部门名称显示Department表
        function Showdivisionmanagement(dname, pageindex, pagesize) {
            $.ajax({
                type: "post",
                url: ApiUrl + "api/Department/SelectPage",
                data: { search: dname, PageIndex: pageindex, PageSize: pagesize },
                success: function (data) {
                    $("#mybody").empty();
                    $("#myfoot").empty();
                    $("#count").text(data.TotalSize);
                    $("#pagecount").text(data.PageCount);
                    $(data.Result).each(function (i, item) {
                        var tr = Array("");
                        tr.push('<tr class="text-c">');
                        tr.push('<td>' + (i + 1) + '</td>');
                        tr.push('<td>' + item.T_DCode + '</td>');
                        tr.push('<td>' + item.T_Dname + '</td>');
                        if (item.T_Depremark == null || item.T_Depremark == 'null') {
                            tr.push('<td></td>');
                        }
                        else {
                            tr.push('<td>' + item.T_Depremark + '</td>');
                        }
                        tr.push('<td class="td-status">');
                        if (this.T_Dstate == 1) {
                            tr.push('<span class="label label-success radius">已启用</span>');
                        }
                        else {
                            tr.push('<span class="label label-default radius">未启用</span>');
                        }
                        tr.push('</td>');
                        tr.push('<td class="td-manage">');
                        if (this.T_Dstate == 1) {
                            tr.push('<a title="停用" href="javascript:;" onclick="admin_stop(' + item.T_DepartmentID + ')" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
                        }
                        else {
                            tr.push('<a title="启用" href="javascript:;" onclick="admin_start(' + item.T_DepartmentID + ')" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
                        }
                        tr.push('<a title="编辑" href="javascript:;" onclick="admin_edit(\'部门编辑\', \'updateDivisionmanagement.html?\', ' + item.T_DepartmentID + ', \'600\', \'350\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>');
                        tr.push('<a title="删除" href="javascript:;" onclick="admin_del(' + item.T_DepartmentID + ',this)" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>');
                        tr.push('</td>');
                        tr.push('</tr>');
                        $("#mybody").append(tr.join(""));
                    });

                    var page = Array();
                    page.push('<tr><td style="text-align:right;" colspan="7">');
                    if (pageindex > 1 && data.PageCount > 0) {
                        page.push('<input type="button"  class="btn btn-primary radius" onclick="Showdivisionmanagement(\'' + dname + '\',' + (pageindex - 1) + ',' + pagesize + ')" value="上一页" />');
                    }
                    page.push('<lable  style="font-size:16px" ">第' + pageindex + '页</label>');
                    if (pageindex < data.PageCount && data.PageCount > 0) {
                        page.push('<input type="button"  class="btn btn-primary radius" onclick="Showdivisionmanagement(\'' + dname + '\',' + (pageindex + 1) + ',' + pagesize + ')" value="下一页" />');
                    }

                    page.push('</tr>');
                    var d1 = page.join("");
                    $("#myfoot").append(d1);
                }
            });

        };

        //根据部门名称查询
        function searchDepartment() {
            var dname = $("#dname_search").val();
            Showdivisionmanagement(dname, 1, 10);
        }

        /*
            参数解释：
            title	标题
            url		请求的url
            id		需要操作的数据id
            w		弹出层宽度（缺省调默认值）
            h		弹出层高度（缺省调默认值）
        */

        /*部门-增加*/
        function admin_add(title, url, w, h) {
            parent.layer_show(title, url, w, h);
        }

        /*部门-删除*/
        function admin_del(id, obj) {
            parent.layer.confirm('确认要删除吗？删除后将无法恢复！', function (index) {
                //此处请求后台程序，下方是成功后的前台处理……
                $.ajax({
                    type: "post",
                    url: ApiUrl + "api/Department/Delete",
                    data: {
                        "": id
                    },
                    success: function (data) {
                        if (data == true) {
                            $(obj).parents("tr").remove();
                            parent.layer.msg('已删除!', { icon: 1, time: 1000 });
                        }
                        else {

                            parent.layer.msg('删除失败!', { icon: 2, time: 1000 });
                        }
                    }
                });

            });
        }

        /*部门-编辑*/
        function admin_edit(title, url, id, w, h) {
            url = url + "?" + id;
            parent.layer_show(title, url, w, h);
        };

        /*部门-停用*/
        function admin_stop(id) {
            parent.layer.confirm('确认要停用吗？', function (index) {
                //此处请求后台程序，下方是成功后的前台处理……
                $.ajax({
                    url: ApiUrl + "api/Department/UpdateState",
                    type: 'post',
                    data: { T_DepartmentID: id, T_Dstate: 0 },
                    success: function (data) {
                        if (data == true) {
                            parent.layer.msg('已停用!', { icon: 5, time: 1000 });
                            window.location.reload(); //刷新
                        }
                        else {
                            parent.layer.msg("停用失败！", { icon: 2, time: 1000 });
                        }
                    }
                });

            });
        };

        /*部门-启用*/
        function admin_start(id) {
            parent.layer.confirm('确认要启用吗？', function (index) {
                $.ajax({
                    url: ApiUrl + "api/Department/UpdateState",
                    type: 'post',
                    data: {
                        T_DepartmentID: id,
                        T_Dstate: 1
                    },
                    success: function (data) {
                        if (data == true) {
                            parent.layer.msg('已启用!', { icon: 6, time: 1000 });
                            window.location.reload(); //刷新
                        }
                        else {
                            parent.layer.msg("启用失败！", { icon: 2, time: 1000 });
                        }
                    }
                });
            });
        }
    </script>
</body>
</html>
